package hn.cch.spring.boot.controller;

import hn.cch.spring.boot.message.Request;
import hn.cch.spring.boot.message.Response;
import hn.cch.spring.boot.service.SessionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;


/**
 * session 是存储在服务器上的类对象
 */
@Controller
@RequestMapping("/session/")
public class SessionController {

    private final static Logger logger = LoggerFactory.getLogger(SessionController.class);

    
    @Autowired
    private SessionService sessionService;


    @RequestMapping("home")
    public void home(){
        logger.info("home");
    }

    @GetMapping("html")
    public String html(HttpServletRequest httpServletRequest){
        sessionService.compareSession(httpServletRequest);
        return "session/home";
    }


    @PostMapping("/json")
    @ResponseBody
    public Response<String> json(@RequestBody Request request){
        logger.info("requestMessage:{}", request);
        Response<String> response = Response.success(UUID.randomUUID().toString());
        logger.info("response:{}", response);
        return response;
    }
}
